//
//  SportDetailModel.m
//  StormWatch
//
//  Created by 王岩 on 2024/9/14.
//

#import "SportDetailModel.h"

@implementation SportDetailModel

+ (instancetype)creatModelWithInfo:(NSArray *)arr {
    SportDetailModel * model = [[SportDetailModel alloc] init];
    
    model.type = [self getSportTypeValue: strtoll([[NSString stringWithFormat:@"0x%@",arr[0]] UTF8String], 0, 16) ];

    model.startTime =strtoll([[NSString stringWithFormat:@"0x%@",arr[1]] UTF8String], 0, 16) ;
    model.sportTime = [NSString stringWithFormat:@"%lld",strtoll([[NSString stringWithFormat:@"0x%@",arr[2]] UTF8String], 0, 16)] ;
    model.stepValue = [NSString stringWithFormat:@"%lld",strtoll([[NSString stringWithFormat:@"0x%@",arr[3]] UTF8String], 0, 16)] ;
    model.caloValue = [NSString stringWithFormat:@"%.3f",strtoll([[NSString stringWithFormat:@"0x%@",arr[4]] UTF8String], 0, 16) / 1000.0] ;
    model.distanceValue = [NSString stringWithFormat:@"%.3f",strtoll([[NSString stringWithFormat:@"0x%@",arr[5]] UTF8String], 0, 16) / 1000.0] ;
    model.rateValue = [NSString stringWithFormat:@"%lld",strtoll([[NSString stringWithFormat:@"0x%@",arr[6]] UTF8String], 0, 16)] ;
    
    model.timeYMDStr = [SWTool timeWithYearMonthDayCountDown:[NSString stringWithFormat:@"%ld",model.startTime] Format:@"yyyy-MM-dd"];
    model.timeHMSStr = [SWTool timeWithYearMonthDayCountDown:[NSString stringWithFormat:@"%ld",model.startTime] Format:@"HH:mm:ss"];
    
    
    return model;
}

+ (SportTypeEnum)getSportTypeValue:(long long)type{
    switch (type) {
        case 2:
            return SportType_Running;
            break;
        case 3:
            return SportType_Riding;
            break; 
        case 4:
            return SportType_RopeSkipping;
            break; 
        case 5:
            return SportType_Swimming;
            break;
        case 8:
            return SportType_Tennis;
            break;
        case 9:
            return SportType_Climbing;
            break;
        case 10:
            return SportType_Walking;
            break;
        case 11:
            return SportType_Basketball;
            break;
        case 12:
            return SportType_Soccer;
            break;
        case 20:
            return SportType_Yoga;
            break;
        case 26:
            return SportType_Workout;
            break;
        case 27:
            return SportType_Weightlifting;
            break;
        default:
            break;
    }
    return 0;
}

@end
